package com.example.demo.mapper;

import com.example.demo.model.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface UserMapper {

    @Insert("insert into user(user_name, password, phone_number) values (#{userName}, #{password}, #{phoneNumber})")
    void insertUser(User user);

    @Select("select * from user where id = #{id}")
    User selectById(Integer id);

    @Select("select * from user where user_name = #{userName}")
    User selectByUserName(String userName);

    @Select("select * from user where admin = 0 limit #{offset}, #{limit}")
    List<User> pageQuery(int limit, int offset);

    @Select("select count(*) from user where admin = 0")
    Long getCount();

    @Update("update user set is_black = true where id = #{id}")
    void setBlack(Integer id);
}
